import axios from 'axios'
// create an axios instance
const service = axios.create({
    baseURL: `http://localhost:8080/renren-fast/`, // url = base url + request url
    timeout: 5000 // request timeout
})

// 添加请求拦截器
service.interceptors.request.use(function (config) {      
  const token = localStorage.getItem('token');
  // 如果有token就带上将token添加到config.headers.Authorization中
  if (token) {            
    config.headers.token = token
  }
  return config
}, function (error) {
  return Promise.reject(error)
})

export default service